package com.situ.wms.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//验证是否登录的过滤器
@WebFilter("/*")
public class LoginFilter implements Filter{

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
	
		HttpServletRequest req=(HttpServletRequest)request;
		String uri=req.getRequestURI();//看看请求是什么
		
		Boolean islogin=req.getSession().getAttribute("currentManager")!=null;
		if(islogin||uri.equals("/login")||uri.equals("/image")||uri.startsWith("/lib/")||uri.startsWith("/js/")||uri.startsWith("/css/")||uri.startsWith("/images"))//如果请求地址是login直接放行，不用判断是否登录
		{
		chain.doFilter(request, response);//放行
		}else 
		{
			HttpServletResponse resp=(HttpServletResponse)response;
			resp.sendRedirect("/login");
		}
	}

}
